package com.bls.cate.ui.activity.publish_manage;

import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.bls.blslib.base.BaseActivity;
import com.bls.cate.R;
import com.bls.cate.adapter.PublishManagerListAdapter;
import com.bls.cate.constant.Interface;
import com.bls.cate.model.ArticleManageListRes;
import com.bls.cate.ui.widget.TitleView;
import com.bls.cate.utils.AccountUtil;
import com.lzy.okgo.cache.CacheMode;
import com.lzy.okgo.model.HttpParams;
import com.lzy.okgo.model.Response;
import com.lzy.okgo.request.base.Request;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 　　  () 　　　  ()
 * 　　  ( ) 　　　( )
 * 　　  ( ) 　　　( )
 * 　　┏┛┻━━━┛┻┓
 * 　　┃　　　━　　　┃
 * 　　┃　┳┛　┗┳　┃
 * 　　┃　　　┻　　　┃
 * 　　┗━┓　　　┏━┛
 * 　　　　┃　　　┃
 * 　　　　┃　　　┗━━━┓
 * 　　　　┃　　　　　　　┣┓
 * 　　　　┃　　　　　　　┏┛
 * 　　　　┗┓┓┏━┳┓┏┛
 * 　　　　　┃┫┫　┃┫┫
 * 　　　　　┗┻┛　┗┻┛
 * ——————————————————
 * Created by BinglingSu on 2018/5/17.
 */
public class PublishManageActivity extends BaseActivity {
    @BindView(R.id.title_view)
    TitleView titleView;
    @BindView(R.id.rv_items)
    RecyclerView rvItems;
    @BindView(R.id.srl_item)
    SwipeRefreshLayout srlItem;


    List<ArticleManageListRes.ResultListDataBean> dataBeanList = new ArrayList<>();
    PublishManagerListAdapter listAdapter = new PublishManagerListAdapter(dataBeanList);


    @Override
    protected void initParams() {

    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_publish_manage;
    }

    @Override
    protected void initFvb() {
        ButterKnife.bind(this);
    }

    @Override
    protected void initTitle() {
        titleView.setBtnMode(1, 0);
        titleView.titleMiddleText.setText("发布管理");
        titleView.setTitleClickListener(new TitleView.OnTitleClickListener() {
            @Override
            public void onTitleClick(int btnType) {
                switch (btnType) {
                    case 1:
                        getActivity().finish();
                        break;
                }
            }
        });
    }

    @Override
    protected void initView() {
        //listAdapter = new PublishManagerListAdapter(dataBeanList);
        LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
        rvItems.setLayoutManager(layoutManager);
        rvItems.setAdapter(listAdapter);
    }

    @Override
    protected void initData() {
        presenter.requestStrData(Interface.INTERFACE_ATTENTION_GET_OWN_ARTICLE, Interface.INTERFACE_ATTENTION, CacheMode.NO_CACHE, new HttpParams("RequestMethod", "ArticleManageList"), new HttpParams("UniqueId", AccountUtil.getUniqueId()));
    }

    @Override
    public void showOnStart(Request request, int requestId) {
        loadingDogDialog.show();
    }

    @Override
    public void showOnSuccess(int requestId, String responseBody, Response response) {
        if (requestId == Interface.INTERFACE_ATTENTION_GET_OWN_ARTICLE) {
            ArticleManageListRes res = gson.fromJson(responseBody, ArticleManageListRes.class);
            if (!res.isResultStatus())
                return;
            dataBeanList = res.getResultListData();
            listAdapter.setNewData(dataBeanList);
        }
    }
}
